﻿// Copyright (c) Vitaly Kamiansky. All rights reserved. 
// See License.txt in the project root.

using Property.Reloaders;
using Property.Workers;
using System;

namespace Property
{
    /// <summary>
    /// Contains words that can come immediately after the opening
    /// of a property description.
    /// </summary>
    public static class ReloadableExtensionsCallbacks
    {
        /// <summary>
        /// <para>... on a worker thread ...</para>
        /// <para>( ! ) Don't forget to dispose of what you create with this word.</para>
        /// <para>New values will be loaded on a worker thread and applied on the UI thread.</para>
        /// </summary>
        /// <param name="testMode">Tell me if I have to switch to single-threaded mode.</param>
        public static IWorkerPrototype<T> Worker<T>(this Reloadable<T> source, bool testMode = false)
        {
            if (source == null) throw new ArgumentNullException("source");

            return testMode ? new ForegroundWorkerPrototype<T>()
                : new BackgroundWorkerPrototype<T>() as IWorkerPrototype<T>;
        }
    }
}
